var app = getApp();
var constract = require('../../utils/constract.js');
Page({
  data: {

  },
  onLoad: function (options) {
    var that=this;
    console.log(options);
    if(options.qr_code === '' || options.qr_code === undefined) {
      app.Verification(function (token) {
        wx.request({
          url: constract.changeCode,
          header: {token: token},
          data: {cardId: options.id},
          success: (res)=>{
            console.log(res);

            that.setData({
              id: options.id,
              avatar: options.avatar,
              name: options.name,
              dimension: res.data.data,
              ouid: options.ouid
            })
          }
        })
      })
    } else {
      app.Verification(function (token) {
        wx.request({
          url: constract.qrCode,
          header:{token:token},
          data: {cardId: options.id},
          success:function(res){
  
            console.log(res);
  
            if(res.data.code!=12000){
              return;
            };
            that.setData({
              id: options.id,
              avatar: options.avatar,
              name: options.name,
              dimension: res.data.data.qr_code,
              ouid: options.ouid
            })
          }
        })
      });
    }
    
  },

  goIndex: function(){
    wx.switchTab({
      url: '../index/index'
    })
  },

  onShareAppMessage: function () {
    var that = this;
    return {
      title: '幸会！这是我名片请惠存！',
      path: '/pages/code/share-code/share-code?qr_code='+that.data.dimension+'&name='+that.data.name+'&avatar='+that.data.avatar+'&id='+that.data.id+'&ouid='+that.data.ouid,
    }
  }
})